import { defineStore, acceptHMRUpdate } from 'pinia'
import { TOKEN, USER_INFO } from '../constant'

export const useUserStore = defineStore('user', {
  state: () => {
    return {
      userInfo: uni.getStorageSync(USER_INFO) || {},
    }
  },
  actions: {
    async login(data){
		uni.setStorageSync(USER_INFO, data);
		uni.setStorageSync(TOKEN, data.token);
		this.userInfo = data
		uni.navigateBack({
			delta: 1
		});
    },
	async logout(data){
		uni.removeStorageSync(USER_INFO)
		uni.removeStorageSync(TOKEN);
		this.userInfo = {}
		uni.navigateTo({
		    url: '/pages/login/login'
		}); 
	}
  },
})
